﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Web.Security;
using System.ComponentModel;

namespace Anuntiomatic.Server
{
    public class BaseMaster : System.Web.UI.MasterPage
    {
        #region Properties
        public int? UserID
        {
            get
            {
                if (string.IsNullOrEmpty(Page.User.Identity.Name))
                {
                    return null;
                }
                else
                {
                    return int.Parse(Page.User.Identity.Name);
                }
            }
            set
            {
                if (value == null)
                {
                    FormsAuthentication.SignOut();
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(value.ToString(), false);
                }
            }
        }

        public string AccessDeniedURL
        {
            get { return ConfigurationManager.AppSettings["AccessDeniedURL"]; }
        }
        public string DefaultURL
        {
            get { return ConfigurationManager.AppSettings["DefaultURL"]; }
        }
        public string ChangePasswordURL
        {
            get { return ConfigurationManager.AppSettings["ChangePasswordURL"]; }
        }
        public string LoginURL
        {
            get { return ConfigurationManager.AppSettings["LoginURL"]; }
        }
        public string ReturnURL
        {
            get
            {
                string returnURL = (string)Session[SESSION.RETURN_URL];
                if (returnURL == null || returnURL == AccessDeniedURL || returnURL == LoginURL) return DefaultURL;
                return returnURL;
            }
            set
            {
                if (Session[SESSION.RETURN_URL] == null)
                    Session.Add(SESSION.RETURN_URL, value);
                else
                    Session[SESSION.RETURN_URL] = value;
            }
        }
        #endregion
        
        protected void RedirectToPage(string urlPage)
        {
            Response.Redirect(urlPage);
        }
    }
}